using System;
using UnityEditor;
using UnityEngine;

namespace Gameplay.PVE.Editor
{
    
    public class RpgAstarEditorWindow : EditorWindow
    {
        [MenuItem("GTATools/GamePlay/PVE/RpgAstarEditor")]
        public static void Init()
        {
            var window = EditorWindow.GetWindow<RpgAstarEditorWindow>("rpg寻路编辑器", true);
            Instance.Initialize();
        }
     
        public static RpgAstarEditorWindow Instance;
        
        public RpgAstarEditorWindow()
        {
            Instance = this;
        }
        
        private void Initialize()
        {
            
        }

        private string heightString = "100";
        private string widthString = "100";
        
        private void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("宽");
            widthString = EditorGUILayout.TextField(widthString);
            EditorGUILayout.EndHorizontal();
            
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("高");
            heightString = EditorGUILayout.TextField(heightString);
            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button("刷新地图"))
            {
                int width;
                int.TryParse(widthString, out width);
                int height;
                int.TryParse(heightString, out height);
                RpgAstarEditorManager.Instance.InitMap(width,height);
            }
            
            if (GUILayout.Button("编辑"))
            {
                RpgAstarEditorManager.Instance.Mode = RpgAstarEditorManager.EAStarEditorMode.EditMap;
            }

            if (GUILayout.Button("寻路"))
            {
                RpgAstarEditorManager.Instance.Mode = RpgAstarEditorManager.EAStarEditorMode.FindPath;
            }
        }

        private void PrepareData()
        {
            
        }
    }

    [CustomEditor(typeof(RpgAstarEditorManager))]
    public class AStarEditorManagerInspector : UnityEditor.Editor
    {
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            if (GUILayout.Button("开始测试"))
            {
                (target as RpgAstarEditorManager).StartPerformanceTest();
            }
        }
    }
}